<?
	if (!defined('i-Teck_ADMIN')) die("Hacking attempt");

	switch($mod){
		case "add":
			
		?>
<form name="form1" method="post" action="">
		<article class="module width_full">
			<header><h3>Thêm Menu</h3></header>
				<div class="module_content">	
				<fieldset>
							<label>Tên Menu</label>
						    <input name="name" type="text" id="name" size="50">
				</fieldset>
				<fieldset>
							<label>Link</label>
						    <input name="url" type="text" id="url" size="50">
				</fieldset>
				
				<input type="submit" name="cmd" id="cmd" value="Thêm" class="alt_btn">
				</div>
		</article><!-- end of styles article -->
</form>
<?
if(isset($_REQUEST["cmd"])=="Thêm"){
		mysql_query("INSERT INTO shop_menu (name,url) values
					('".addslashes($_POST["name"])."',
					'".addslashes($_POST["url"])."')");
	//mysql_query("insert into shop_nemu (name,url) 
		//		values ('".addslashes($_POST["name"])."'),'".addslashes($_POST["url"])."')");
	mysql_close();
	echo "<meta http-equiv='refresh' content='0; url=?act=menu&mod=view'>";
	}
	break;
	case "view":
	$result=mysql_query("SELECT * FROM shop_menu ORDER BY STT");
	if(mysql_num_rows($result)<=0){echo"<center><font color=red>Chưa có dữ liệu</font></center>";}
	else{
	?>

<form id="form2" name="form2" method="post" action="">

	<article class="module width_full">
			<header><h3>Quản lý Menu</h3></header>
	
		<div class="tab_container">
			<div id="tab1" class="tab_content">
			<table class="tablesorter" cellspacing="0"> 
			<thead> 
				<tr> 
    				<th>STT</th> 
    				<th>Tên Menu</th> 
    				<th>Sửa</th> 
    				<th>Xóa</th>
				</tr> 
			</thead> 
			<tbody> 


    <?  while($r=mysql_fetch_array($result)){?>
				<tr> 
   					<td><input name="stt[]" type="text" value="<?=$r['stt'];?>" size="2" /><input name="id[]" type="text" value="<?=$r['id'];?>" style="display:none" /></td> 
    				<td><a href="?act=menu&amp;mod=edit&amp;id=<? echo $r['id'];?>"><? echo stripslashes($r['name']);?></a></td> 
    				<td><a href="?act=menu&amp;mod=edit&amp;id=<? echo $r['id'];?>">Sửa</a></td> 
    				<td><a onclick="return  confirm('Bạn có muốn xóa Menu này ko?');" href="?act=menu&amp;mod=delete&amp;id=<? echo $r['id'];?>">Xóa</a></td> 
				</tr> 
    
    <? }}?>
    <tr>
      <td><input type="submit" name="cmd" id="cmd" value="Sửa thứ tự" class="alt_btn"/></td>
    </tr>

			</tbody> 
			</table></div></div>
		</article><!-- end of styles article -->
</form>

<? 
if(isset($_POST["cmd"])=="Sửa thứ tự"){
		$id=$_POST["id"];
		$stt=$_POST["stt"];
		$lap=count($_POST["id"]);
		for($i=0;$i<$lap;$i++){
		mysql_query("UPDATE shop_menu SET stt=".$stt[$i]." WHERE id=".$id[$i]."");

			}
	
		echo "<meta http-equiv='refresh' content='0; url=?act=menu&mod=view'>";
	}

break;
		case "edit":
		$id=intval($_REQUEST["id"]);
		$result=mysql_query("select * from shop_menu where id=$id");
		if(mysql_num_rows($result)<=0){echo"<center><font color=red>Chưa có dữ liệu</font</center>";}
		else{
		?>
        <form name="form1" method="post" action="">
	<article class="module width_full">
			<header><h3>Sửa Menu</h3></header>
				<div class="module_content">	
				<fieldset>
							<label>Tên Menu</label>
						    <? while($r=mysql_fetch_array($result)){ ?>
							<input name="name" type="text" value="<? echo stripslashes($r["name"]);?>" size="50">
				</fieldset>
				<fieldset>
							<label>Link</label>
							<input name="url" type="text" value="<? echo stripslashes($r["url"]);?>" size="50"><? }?>
				</fieldset>
				
				<input type="submit" name="cmd" id="cmd" value="Sửa" class="alt_btn">
				</div>
		</article><!-- end of styles article -->
</form>
		
	<? } if(isset($_REQUEST["cmd"])=="Sửa"){
		mysql_query("update shop_menu set name='".addslashes($_POST["name"])."' where id=$id");
		mysql_query("update shop_menu set url='".addslashes($_POST["url"])."' where id=$id");
		mysql_close();
		echo "<meta http-equiv='refresh' content='0; url=?act=menu&mod=view'>"; }
	
	break;
	case "delete":
		$id=intval($_REQUEST["id"]);
		mysql_query("delete from shop_menu where id=$id");
		mysql_close();
		echo "<meta http-equiv='refresh' content='0; url=?act=menu&mod=view'>";
	break;
	
	} 
	?>

